package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.enterprise.ProfessionalTeamPictureEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamPictureActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ProfessionalTeamPictureModel extends BaseViewModel {

    private ProfessionalTeamPictureActivity professionalTeamPictureActivity;

    public ProfessionalTeamPictureModel(ProfessionalTeamPictureActivity professionalTeamPictureActivity) {
        this.professionalTeamPictureActivity = professionalTeamPictureActivity;
    }


    public void getPicture(String teamNo,int page,int limit) {
        professionalTeamPictureActivity.loading();
        DialogHelper.showProgressDialog(professionalTeamPictureActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPicture(teamNo,page,limit).enqueue(new Callback<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>> call, Response<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    professionalTeamPictureActivity.setShowPicture(new ArrayList<>());
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    professionalTeamPictureActivity.setShowPicture(response.body().getData().getList());
                    professionalTeamPictureActivity.success();
                } else {
                    MToast.showToast(professionalTeamPictureActivity, response.body().getMsg());
                    professionalTeamPictureActivity.setShowPicture(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                professionalTeamPictureActivity.setShowPicture(new ArrayList<>());
            }
        });
    }


    /**
     * 团队相册
     */
    public void getPictureUserCenter(int page,int limit) {
        professionalTeamPictureActivity.loading();
        DialogHelper.showProgressDialog(professionalTeamPictureActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getPictureUserCenter(page,limit).enqueue(new Callback<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>> call, Response<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    professionalTeamPictureActivity.setShowPicture(new ArrayList<>());
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    professionalTeamPictureActivity.setShowPicture(response.body().getData().getList());
                    professionalTeamPictureActivity.success();
                } else {
                    MToast.showToast(professionalTeamPictureActivity, response.body().getMsg());
                    professionalTeamPictureActivity.setShowPicture(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<ProfessionalTeamPictureEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                professionalTeamPictureActivity.setShowPicture(new ArrayList<>());
            }
        });
    }

}